using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Web.DataAccess.Factories;
using Web.HelperClasses;
using Web.HelperClasses.Inflexion;
using Web.NetworkWorkers;
using Web.Security;
using Web.HelperClasses.AvatarService;

namespace Web
{
    public class ApplicationComponents : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Component.For<IAuthorizationService>().ImplementedBy<AuthorizationService>().LifeStyle.Transient);
			container.Register(Component.For<AvatarService>().ImplementedBy<UserAvatarService>().LifeStyle.Transient);
            container.Register(Component.For<YandexFotki>().ImplementedBy<YandexFotki>().LifeStyle.Singleton.UsingFactoryMethod(YandexFotki.GetInstance));
			container.Register(Component.For<HttpClient>().ImplementedBy<HttpClient>().LifeStyle.Transient);
        	ConfigureInflector(container);
        }

    	private static void ConfigureInflector(IWindsorContainer container)
    	{
    		container.Register(Component.For<INetworkHelper>().ImplementedBy<NetworkHelper>());
			container.Register(Component.For<IInflectionQueryFactory>().ImplementedBy<InflectionQueryFactory>().LifeStyle.Singleton);
			container.Register(Component.For<IInflectionFactory>().ImplementedBy<InflectionFactory>().LifeStyle.Singleton);

			container.Register(Component.For<SQLInflector>().ImplementedBy<SQLInflector>().LifeStyle.Transient);
			container.Register(Component.For<YaInflector>().ImplementedBy<YaInflector>().LifeStyle.Transient);
    		container.Register(Component.For<IInflector>()
    		                   	.ImplementedBy<CompositeInflector>()
    		                   	.LifeStyle.Transient
								.UsingFactoryMethod(() =>
								                    	{
								                    		var inflector = new CompositeInflector();
															inflector.AddInflector(container.Resolve<SQLInflector>());
															inflector.AddInflector(container.Resolve<YaInflector>());
								                    		return inflector;
								                    	}));
			container.Register(Component.For<IWordFormatter>().ImplementedBy<WordFormatter>().LifeStyle.Transient);
    	}
    }
}